package com.whalefin.controller.adminUser;


import com.whalefin.domain.AdminUser;
import com.whalefin.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;


/**
* Created by sf on 14-4-28.
*/
@Controller
@RequestMapping("/adminUser/loginSubmit")
public class LoginController {

	@Autowired
	private LoginService loginService;

    @RequestMapping(method = RequestMethod.GET)
    public String login() {

        return "black/admin/adminLogin";

    }

    /**
     * 查询是否存在管理员用户
     * @param loginName
     * @param loginPassword
     * @return
     */
	@RequestMapping(method = RequestMethod.POST)
	public String login(@RequestParam String loginName,@RequestParam String loginPassword,HttpServletRequest request) {
        AdminUser adminUser = loginService.queryLoginUser(loginName,loginPassword);
        if(adminUser != null){
            request.getSession().setAttribute("adminUser",adminUser);
            return "redirect:/leaveMessage/leaveMessageList";
        }else{
            return "black/admin/error";
        }
    }
}
